NMEA: Parse time in GPGLL's as doubles, not ints, to preserve sscanf state for 'valid...
authorrobertl <robertl>
Mon, 17 Mar 2008 16:56:29 +0000 (16:56 +0000)
committerrobertl <robertl>
Mon, 17 Mar 2008 16:56:29 +0000 (16:56 +0000)
nmea.c

diff --git a/nmea.c b/nmea.c
index de9ae50c48c85238f41f999279d11e798edb7d9c..5324f7fabc3f5db1ef630da974d95f219c257e74 100644 (file)
--- a/nmea.c
+++ b/nmea.c
@@ -371,8 +371,9 @@ nmea_set_waypoint_time(waypoint *wpt, struct tm *time, int microseconds)
 static void
 gpgll_parse(char *ibuf)
 {
-       double latdeg, lngdeg;
+       double latdeg, lngdeg, microseconds;
        char lngdir, latdir;
+       double hmsd;
        int hms;
        char valid = 0;
        waypoint *waypt;
@@ -382,14 +383,17 @@ gpgll_parse(char *ibuf)
                track_add_head(trk_head);
        }
 
-       sscanf(ibuf,"$GPGLL,%lf,%c,%lf,%c,%d,%c,",
+       sscanf(ibuf,"$GPGLL,%lf,%c,%lf,%c,%lf,%c,",
                &latdeg,&latdir,
                &lngdeg,&lngdir,
-               &hms,&valid);
+               &hmsd,&valid);
 
        if (valid != 'A')
                return;
 
+       hms = (int) hmsd;
+       microseconds = MILLI_TO_MICRO(1000 * (hmsd - hms));
+
        tm.tm_sec = hms % 100;
        hms = hms / 100;
        tm.tm_min = hms % 100;
@@ -400,7 +404,7 @@ gpgll_parse(char *ibuf)
 
        waypt = waypt_new();
 
-       nmea_set_waypoint_time(waypt, &tm, 0);
+       nmea_set_waypoint_time(waypt, &tm, microseconds);
 
        if (latdir == 'S') latdeg = -latdeg;
        waypt->latitude = ddmm2degrees(latdeg);